
#include "EGWindow.hpp"

EG_NAMESPACE_BEGIN(EG_WIN)


LRESULT CALLBACK EgWindow::WndProc(
    HWND hWnd,
    UINT msgId,
    WPARAM wParam,
    LPARAM iParam
) {
    switch (msgId) {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
            break;
        case WM_PAINT: {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hWnd, &ps);
            RECT rect;
            GetClientRect(hWnd, &rect);
            DrawText(hdc, _T("Hello from main()!"), -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
            EndPaint(hWnd, &ps);
            return 0;
        }
        case WM_SHOWWINDOW:

            break;
    }

    return DefWindowProc(hWnd, msgId, wParam, iParam);
}

bool EgWindow::egWindowInit() {
    wc = {0};
    hWnd = NULL;
    argvW = CommandLineToArgvW(GetCommandLineW(), &argcW);
    hIns = GetModuleHandle(NULL);
    /*注册窗口*/

    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wc.hCursor = NULL;
    wc.hIcon = NULL;
    wc.hInstance = hIns;
    wc.lpfnWndProc = WndProc;
    wc.lpszClassName = _T("EG");
    wc.lpszMenuName = NULL;
    wc.style = CS_HREDRAW | CS_VREDRAW;

    RegisterClass(&wc);

    hWnd = CreateWindow(
        wc.lpszClassName,
         _T("EG_Window"),
        WS_OVERLAPPEDWINDOW,
        100,
        100,
        600,
        400,
        NULL,
        NULL,
        hIns,
        NULL
    );


    return true;
}

void EgWindow::show() {
    ShowWindow(hWnd, SW_SHOW);
    UpdateWindow(hWnd);

}

void EgWindow::hide() {
    ShowWindow(hWnd, SW_HIDE);
    UpdateWindow(hWnd);
}


EgWindow::EgWindow(/* args */) {
    egWindowInit();

}
        
EgWindow::~EgWindow() {
    LocalFree(argvW);

}


EG_NAMESPACE_END

